package com.vision.sales.cl.data;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor.Path;
import com.google.gwt.i18n.shared.DateTimeFormat;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.PropertyAccess;
import com.vision.sales.cm.data.TransactionStatus;
import com.vision.sales.cm.db.data.AdvancePayment;
import com.vision.sales.cm.db.data.AppliedAdvancePayment;

/**
 * 
 * @author Mark
 *
 */
public interface AppliedAdvancePaymentProperties extends PropertyAccess<AppliedAdvancePayment> {
	
	public static final AppliedAdvancePaymentProperties INSTANCE = GWT.create(AppliedAdvancePaymentProperties.class);
	
	@Path("id")
	ModelKeyProvider<AppliedAdvancePayment> key();
	
	@Path("advancePayment.advancePaymentNo")
	LabelProvider<AppliedAdvancePayment> nameLabel();
	
	@Path("advancePayment.displayText") // Dummy path
	AdvancePaymentLabelValueProvider advancePaymentText();
	
	ValueProvider<AppliedAdvancePayment, Long> id();
	
	@Path("advancePayment.advancePaymentNo")
	ValueProvider<AppliedAdvancePayment, String> advancePaymentNo();
	
	@Path("salesInvoice.invoiceNo")
	ValueProvider<AppliedAdvancePayment, String> salesInvoiceNo();
	
	@Path("salesInvoice.date")
	ValueProvider<AppliedAdvancePayment, Date> salesInvoiceDate();
	
	ValueProvider<AppliedAdvancePayment, Double> appliedAmount();
	
	ValueProvider<AppliedAdvancePayment, TransactionStatus> status();
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	public static class AdvancePaymentLabelValueProvider implements ValueProvider<AppliedAdvancePayment, String> {
		
		static final DateTimeFormat format = DateTimeFormat.getFormat("MM/dd/yyyy");

		@Override
		public String getValue(AppliedAdvancePayment object) {
			AdvancePayment payment = object.getAdvancePayment();
			return format.format(payment.getDate()) + "    " + payment.getAdvancePaymentNo() + "    " + payment.getAmount();
		}

		@Override
		public void setValue(AppliedAdvancePayment object, String value) {
			// Do nothing
		}

		@Override
		public String getPath() {
			return "advancePayment.displayText";
		}
		
	}

}
